package com.hnhs.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hnhs.info.PageInfo;
import com.hnhs.mapper.CategoryMapper;
import com.hnhs.model.Category;
import com.hnhs.model.CategoryQuery;
import com.hnhs.threadLocal.LocalPageInfoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper mapper;

    public List<Category> findAll(){

        return mapper.findAll();
    }

    public List<Category> select(CategoryQuery query){
        // 解决不分页的时候 查询所有数据
//        if(query.getPageNum() != null && query.getPageSize()!=null){
//            PageHelper.startPage(query.getPageNum(),query.getPageSize());
//        }
//
//        List<Category> categoryList = mapper.select(query);
//        if(categoryList instanceof Page){
//            Page page = (Page) categoryList;
//            Long total = page.getTotal();
//            System.out.println(total);
//            LocalPageInfoUtil.set(PageInfo.builder().total(total).build());
//        }

        return mapper.select(query);
    }

   public int insert(Category category){
        //交给你们作 里面加个判断
        return mapper.insert(category);
    }
   public  int update(Category category){
        return mapper.update(category);
    }
    //删除 采用软删除 就是更改status
    public int delete(Integer id){

        return mapper.updateStatus(id,1);
    }
}
